import { getlistApi, addlistApi, updateApi, deleteApi } from '@/api/classify'

export default {
  namespaced: true,
  state: {
    classifyList: []
  },
  mutations: {
    SET_LIST(state, data) {
      // console.log(data);
      state.classifyList = [{}].concat(data)
      // console.log(state.classifyList);
    },
  },
  actions: {
    // 渲染
    async getList({ commit },) {
      const { data } = await getlistApi({});
      // console.log(data);
      commit("SET_LIST", data)
    },
    // 新增
    async addlist({ dispatch }, form) {
      await addlistApi(form)
      // dispatch('getList')
    },
    // 删除
    async delList({ dispatch }, id) {
      await deleteApi(id)
      await dispatch('getList')
    },
    // 修改
    async updateList({ dispatch }, form) {
      await updateApi(form)
      dispatch('getList')
    }
  },
  getters: {

  },
  modules: {

  }
}